package com.sinven.common;

public class Pager<T> {

	private long totalRecords;// 总记录数

	private long totalPages;// 总页数

	private long curPage = 1;// 当前页

	private Integer pageSize = 5;// 每页显示数

	private long startIndex;// 起始索引

	private T data;// 每页的内容

	public Pager(long totalRecords, Long curPage, Integer pageSize) {
		if (totalRecords > 0) {
			this.totalRecords = totalRecords;
		}
		if (pageSize != null && pageSize > 0) {
			this.pageSize = pageSize;
		}
		this.totalPages = this.totalRecords % this.pageSize == 0 ? this.totalRecords / this.pageSize
				: this.totalRecords / this.pageSize + 1;
		if (curPage != null && curPage > 0) {
			this.curPage = curPage;
		}
		if (this.curPage > this.totalPages) {
			this.curPage = this.totalPages;
		}
		this.startIndex = (this.curPage - 1) * this.pageSize;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public long getTotalRecords() {
		return totalRecords;
	}

	public long getTotalPages() {
		return totalPages;
	}

	public long getCurPage() {
		return curPage;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public long getStartIndex() {
		return startIndex;
	}
}